package com.gzwanchuang.lszg.adapter;

import android.widget.RadioGroup;

import androidx.annotation.NonNull;

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.gzwanchuang.lszg.R;
import com.ruffian.library.widget.RRadioButton;

import java.util.List;

public class PolicyItemAdapter extends BaseMultiItemQuickAdapter<PolicyItemBean, BaseViewHolder> {

    public PolicyItemAdapter(List<PolicyItemBean> data) {
        super(data);
        // 绑定 layout 对应的 type
        addItemType(PolicyItemBean.TITLE, R.layout.item_policy_item_title);
        addItemType(PolicyItemBean.CONTENT_ONE, R.layout.item_policy_item_number);
        addItemType(PolicyItemBean.CONTENT_TWO, R.layout.item_policy_item_check);
        addItemType(PolicyItemBean.CONTENT_THREE, R.layout.item_policy_item_null);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, PolicyItemBean item) {
        // 根据返回的 type 分别设置数据
        switch (helper.getItemViewType()) {
            case 0:
                helper.setText(R.id.tv_goods_name, item.getPolicy_name());
                break;
            case 1:
                helper.setText(R.id.tv_goods_name, item.getPolicy_name());
                if (item.getType().equals("1")) {
                    helper.setText(R.id.tv_number, item.getPolicy_value() + "元");
                } else {
                    helper.setText(R.id.tv_number, item.getPolicy_value() + "%");
                }
                break;
            case 2:
                helper.setText(R.id.tv_goods_name, item.getPolicy_name());
                if (item.getPolicy_value().equals("0")) {
                    helper.<RRadioButton>getView(R.id.rb_one).setChecked(true);
                } else {
                    helper.<RRadioButton>getView(R.id.rb_two).setChecked(true);
                }
                helper.<RadioGroup>getView(R.id.rg_group).setOnCheckedChangeListener((group, checkedId) -> {
                    if (checkedId == R.id.rb_one) {
                        item.setPolicy_value("0");
                    } else {
                        item.setPolicy_value("1");
                    }
                });
                break;
            case 3:
                break;
            default:
                break;
        }
    }
}